home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / dsp / 96000tar.z / 96000tar / 96000 / appb / b143a.asm < prev    next >
Assembly Source File  |  1992-04-28  |  5KB  |  97 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.43    Line Drawing  
  8. ; B.1.43.1    Floating-Point Incremental Line Drawing Algorithm  
  9. ;This algorithm generates points along a line given the endpoints. As the  coordinate along one axis is 
  10. ;incremented in fixed point, the other  coordinate is incremented in floating-point and then converted 
  11. ;to fixed  point.  A full line drawing algorithm which draws lines in all  directions is given below.  
  12. ;Registers: 
  13. ;  d0 = temporary      d4 = temporary x1     d8 = 
  14. ;  d1 = temporary      d5 = temporary y1     d9 = 2.0 
  15. ;  d2 = x1 (dx)        d6 = x0 and xScreen 
  16. ;  d3 = y1 (dy)        d7 = y0 and yScreen 
  17. ;                                                           Program    ICycles 
  18.                                                              Words 
  19. ; Calculate dx and dy 
  20.   fsub.s d6,d2  d2.s,d4.s                                ;  1    1 
  21.   fsub.s d7,d3  d3.s,d5.s                                ;  1    1 
  22. ; Determine whether to increment x or y 
  23.   fcmpm  d3,d2                                           ;  1    1 
  24.   fjge   _inc_x                                          ;  2    2 
  25. ; Switch endpoints if necessary 
  26. _inc_y 
  27.   ftst   d3                    d2.s,d0.s                 ;  1    1 
  28.   ftfr.s d4,d6                 fflt                      ;  1    1 
  29.   ftfr.s d5,d7                 fflt                      ;  1    1 
  30. ; Fix y0 and dy 
  31.   int    d7                    d3.s,d1.s                ;   1    1 
  32.   int    d1                                              ;  1    1 
  33.   neg    d1                    iflt                      ;  1    1 
  34.   jeq    _draw1_y                                        ;  2    2 
  35. ; Calculate dx/dy 
  36.   fseedd d3,d4                                           ;  1    1 
  37.   fmpy.s d3,d4,d5              d9.s,d2.s                 ;  1    1 
  38.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                 ;  1    1 
  39.   fmpy.s d5,d2,d5              d2.s,d4.s                 ;  1    1 
  40.   fmpy   d0,d4,d0 fsub.s d5,d3                           ;  1    1 
  41.   fmpy.s d0,d3,d0              d6.s,d2.s                 ;  1    1 
  42. ; Draw first point                                       ;
  43.   int    d6                                              ;  1    1 
  44.   jsr    _draw_point                        ;  application dependent 
  45. ; d0 = dx/dy  d1 = dy  d6 = x0  d7 = y0 
  46.   do     d1.l,_end_y                                     ;  2    3 
  47.   fadd.x d0,d2                                           ;  1    1 
  48.   inc    d7                    d2.s,d6.s                 ;  1    1 
  49.   int    d6                                              ;  1    1 
  50.   jsr    _draw_point                        ;  application dependent 
  51. _end_y 
  52.   rts                                                    ;  2    2 
  53.  
  54. _draw1_y 
  55.   int d6                                                 ;  1    1 
  56.   jsr    _draw_point                        ;  application dependent 
  57.   rts                                                    ;  2    2 
  58. ; Switch endpoints if necessary 
  59. _inc_x 
  60.   ftst   d2                    d3.s,d0.s                 ;  1    1 
  61.   ftfr.s d4,d6                 fflt                      ;  1    1 
  62.   ftfr.s d5,d7                 fflt                      ;  1    1 
  63. ; Fix x0 and dx                                          ;
  64.   int    d6                    d2.s,d1.s                 ;  1    1 
  65.   int    d1                                              ;  1    1 
  66.   neg    d1                    iflt                      ;  1    1 
  67.   jeq                          _draw1_x                  ;  2    2 
  68. ; Calculate dy/dx                                        ;
  69.   fseedd d2,d4                                           ;  1    1 
  70.   fmpy.s d2,d4,d5              d9.s,d2.s                 ;  1    1 
  71.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                 ;  1    1 
  72.   fmpy.s d5,d2,d5              d2.s,d4.s                 ;  1    1 
  73.   fmpy   d0,d4,d0 fsub.s d5,d3                           ;  1    1 
  74.   fmpy.s d0,d3,d0              d7.s,d2.s                 ;  1    1 
  75. ; Draw first point                                       ;
  76.   int    d7                                              ;  1    1 
  77.   jsr    _draw_point                        ;  application dependent 
  78. ; d0 = dy/dx  d1 = dx  d6 = x0  d7 = y0 
  79.   do     d1.l,_end_x                                     ;  2    3 
  80.   fadd.x d0,d2                                           ;  1    1 
  81.   inc    d6                    d2.s,d7.s                 ;  1    1 
  82.   int    d7                                              ;  1    1 
  83.   jsr    _draw_point                        ;  application dependent 
  84. _end_x                                                   ;
  85.   rts                                                    ;  2    2 
  86. _draw1_x                                                 ;
  87.   int d7                                                 ;  1    1 
  88.   jsr    _draw_point                        ;  application dependent 
  89.   rts                                                    ;  2    2 
  90.  
  91.  
  92. ;Performance: 
  93. ;  Trivial case: (single point)  16      cycles 
  94. ;  Other cases:                  25 + 3n cycles 
  95.